cd  "\\micro.intra\Projekt\P0624$\P0624_Gem\Kitschelt\submission"
log using regressions_main_pol, replace
use main_data_pol, clear
***Regressions for Table 1
xi: reg x  pdum_G  if pos==1 |pos==3
 outreg2 using Table_1, dec(2)  se replace excel
foreach samp in sm gb {
	foreach var in x y{
		xi: reg  std_`var' dum_`samp'  if samp_`samp'==1
		outreg2 using Table_1, dec(2) append excel
		xi: areg std_`var'  dum_`samp' if samp_`samp'==1, abs(my)
		outreg2 using Table_1, dec(2)se append excel
		xi: areg   std_`var' dum_`samp'  age  age_ret single nordic european non_european  if samp_`samp'==1, abs(my)
		outreg2 using Table_1, dec(2)  se append excel
		xi: areg std_`var'  dum_`samp'  poor_par  rich_par    `var'_father_adol  `var'_mother_adol  `var'_parhom `var'_fath_hom  age  age_ret single nordic european non_european  if samp_`samp'==1  & poor_par!=. & rich_par!=. & `var'_pardiff !=. , abs(my)
		outreg2 using Table_1, dec(2)  se append excel
		xi: areg  std_`var' dum_`samp' par_G par_B  par_S par_M age  age_ret single nordic european non_european   if samp_`samp'==1  , abs(my)
		outreg2 using Table_1, dec(2)  se append excel
		xi: areg std_`var'  dum_`samp'  sib_`var' age  age_ret single nordic european non_european  if samp_`samp'==1  , abs(my)
		outreg2 using Table_1, dec(2)  se append excel
		xi: areg std_`var'  dum_`samp'  age  age_ret single nordic european non_european   if samp_`samp'==1,  abs(  par_id  ) 
		outreg2 using Table_1, dec(2)  se append excel
	}
}

*Regressions for Table W7
xi: reg std_y  dum_gb if samp_gb==1  & poor_par!=. & rich_par!=. & y_pardiff !=. 
outreg2 using Table_W7, dec(2)   replace excel
foreach samp in  gb  sm {
foreach var in  y x{
		xi: reg std_`var'  dum_`samp' if samp_`samp'==1  & poor_par!=. & rich_par!=. & `var'_pardiff !=. 
		outreg2 using Table_W7, dec(2)  se append excel
		xi: reg  std_`var' dum_`samp'  if samp_`samp'==1  &  party_parent!=""
		outreg2 using Table_W7, dec(2)  se append excel
		xi: reg std_`var'  dum_`samp' if samp_`samp'==1  & sib_`var'!=. 
		outreg2 using Table_W7, dec(2)  se append excel
		xi: reg std_`var'  dum_`samp'  if samp_`samp'==1   & par_id!=. 
		outreg2 using Table_W7, dec(2)  se append excel
	}
}

****Descriptive statistics for Table W8, saved to log file
*log using party_means, replace
sum  y galtan_pct  ConcOther AssCareOther NegConSolv ServOriCare SocPercep  ConMacProc DocRecInfo HandMoveObj InterComp AdminAct  education educ_year sex  x  stdoffshore_pct sector PrivSec-NonProfit cap_exec_alt inc_pct_emp   busink OpFtgLedare BusPers if x!=. & y!=.
bysort parti_initial: sum  y galtan_pct  ConcOther AssCareOther NegConSolv ServOriCare SocPercep  ConMacProc DocRecInfo HandMoveObj InterComp AdminAct  education educ_year sex  x  stdoffshore_pct sector PrivSec-NonProfit cap_exec_alt inc_pct_emp   busink OpFtgLedare BusPers   if x!=. & y!=. 
*log close
 
*Regressions for Table W9
xi: reg x  pdum_G  if pos==1 |pos==3
outreg2 using Table_W9, dec(2)  se replace excel
foreach samp in gb sm {
	foreach alt in  first_nom   {
		foreach var in std_y std_x {
			xi: reg `var'_`alt' dum_`samp'  if samp_`samp'==1
			outreg2 using Table_W9, dec(2) append excel
			xi: areg `var'_`alt'  dum_`samp' if samp_`samp'==1, abs(my)
			outreg2 using Table_W9, dec(2)se append excel
			xi: areg  `var'_`alt' dum_`samp'  age  age_ret single nordic european non_european  if samp_`samp'==1, abs(my)
			outreg2 using Table_W9, dec(2)  se append excel ctitle(`var'_`alt')
		}
	}
}
*Regressions for Table W10
xi: reg x  pdum_G  if pos==1 |pos==3
outreg2 using Table_W10, dec(2)  se replace excel
foreach samp in gb sm {
	foreach alt in avg noimput nopbb 05pbb  {
		foreach var in std_y std_x {
			xi: reg `var'_`alt' dum_`samp'  if samp_`samp'==1
			outreg2 using Table_W10, dec(2) append excel
			xi: areg `var'_`alt'  dum_`samp' if samp_`samp'==1, abs(my)
			outreg2 using Table_W10, dec(2)se append excel
			xi: areg  `var'_`alt' dum_`samp'  age  age_ret single nordic european non_european  if samp_`samp'==1, abs(my)
			outreg2 using Table_W10, dec(2)  se append excel ctitle(`var'_`alt')
		}
	}
}

*Regressions for Table W11
xi: reg x  pdum_G  if pos==1 |pos==3
outreg2 using Table_W11, dec(2)  se replace excel
foreach samp in gb sm {
	foreach alt in  eq std istd wistd ma wma   {
		foreach var in std_y std_x {
			xi: reg `var'_`alt' dum_`samp'  if samp_`samp'==1
			outreg2 using Table_W11, dec(2) append excel
			xi: areg `var'_`alt'  dum_`samp' if samp_`samp'==1, abs(my)
			outreg2 using Table_W11, dec(2)se append excel
			xi: areg  `var'_`alt' dum_`samp'  age  age_ret single nordic european non_european  if samp_`samp'==1, abs(my)
			outreg2 using Table_W11, dec(2)  se append excel ctitle(`var'_`alt')
		}
 }
	foreach var in std_pc1 std_pc2 {
		xi: reg `var' dum_`samp'  if samp_`samp'==1
		outreg2 using Table_W11, dec(2) append excel
		xi: areg `var'  dum_`samp' if samp_`samp'==1, abs(my)
		outreg2 using Table_W11, dec(2) se append excel
		xi: areg  `var' dum_`samp'  age  age_ret single nordic european non_european  if samp_`samp'==1, abs(my)
		outreg2 using Table_W11, dec(2)  se append excel ctitle(`var'_`alt')
	}
}

****Tables W15-17

gl egp egp_2 egp_7  egp_6 egp_3 egp_4 egp_5
gl oesch8  oesch_8cat_8  oesch_8cat_4  oesch_8cat_7  oesch_8cat_3  oesch_8cat_5  oesch_8cat_1  oesch_8cat_2 
gl kitrehm_a a_associate a_skill a_unskill
gl kitrehm a_associate a_skill a_unskill t_tech t_inter ta_skill_tech ta_skill_int
gl kitrehm_t t_tech t_inter
gl kitrehm_at ta_skill_tech ta_skill_int ta_unskill
gl kitrehm_ie hi_he li_he hi_le
gl richpoor poor_par  rich_par
gl y_par y_father_adol  y_mother_adol  y_parhom y_fath_hom
gl x_par x_father_adol  x_mother_adol  x_parhom x_fath_hom
gl party_par par_G par_B  par_S par_M 
gl y_sibling  sib_y 
gl x_sibling   sib_x
***Tables W15A and W15B

xi: reg y dum_gb dum_sm
outreg2 using Table_W15, dec(2)  se replace excel
foreach samp in  sm gb {
	foreach var in y x{
		reg std_`var' dum_`samp' $egp  if samp_`samp'==1 
		outreg2 using Table_W15, dec(2)  se append excel
		xi : reg std_`var' dum_`samp' $oesch8      if samp_`samp'==1 
		outreg2 using Table_W15, dec(2)  se append excel
		reg std_`var' dum_`samp'  $kitrehm if samp_`samp'==1 
		outreg2 using Table_W15, dec(2)  se append excel
	}
}
*Table W16A-G
  
foreach scheme in y_sibling x_sibling richpoor  oesch8 egp kitrehm_a kitrehm_t kitrehm_at y_par x_par party_par{
    xi: reg y $`scheme' 
	outreg2 using kit_`scheme', dec(2)  se replace excel
foreach samp in gb sm {
		xi: reg dum_`samp' $`scheme'  if samp_`samp'==1
		outreg2 using kit_`scheme', dec(2)  se append excel
		xi: reg dum_`samp' $`scheme' y  if samp_`samp'==1
		outreg2 using kit_`scheme', dec(2)  se append excel
		xi: reg dum_`samp' $`scheme' x  if samp_`samp'==1
		outreg2 using kit_`scheme', dec(2)  se append excel
	}
}

foreach scheme in y_par x_par{
	xi: reg y $`scheme' 
	outreg2 using kit_`scheme', dec(2)  se replace excel
	xi: reg x $`scheme' 
	outreg2 using kit_`scheme', dec(2)  se append excel
	foreach samp in gb sm {
		xi: reg dum_`samp' $`scheme'  if samp_`samp'==1
		outreg2 using kit_`scheme', dec(2)  se append excel
		xi: reg dum_`samp' $`scheme' y  if samp_`samp'==1
		outreg2 using kit_`scheme', dec(2)  se append excel
		xi: reg dum_`samp' $`scheme' x  if samp_`samp'==1
		outreg2 using kit_`scheme', dec(2)  se append excel
	}
}

***Table W17
*log using table_W17, replace
gen ssyk3=substr(Ssyk4,1,3)
foreach p in G B S M {
	tab ssyk3  if parti_initial=="`p'"
}

tabstat x y, by(ssyk3)
*log close


log close
